import Vue from 'vue'
import App from './App.vue'
import router from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import {deleteRequest, getRequest, postRequest, putRequest} from "./utils/api";
import store from './store/index.js'
import {initMenu} from "./utils/menu";
import 'font-awesome/css/font-awesome.css'
import {downloadRequest} from "./utils/download";
Vue.config.productionTip = false//关闭环境配置信息
Vue.use(ElementUI,{size:'small'});//全局每次加载small
Vue.prototype.postRequest=postRequest;
Vue.prototype.putRequest=putRequest;
Vue.prototype.getRequest=getRequest;
Vue.prototype.deleteRequest=deleteRequest;
Vue.prototype.downloadRequest = downloadRequest;


/*导航路由守卫 就是跳转前或后要做什么 相当于拦截器*/
router.beforeEach((to,from,next)=>{
 if (window.sessionStorage.getItem('tokenStr')){
   initMenu(router,store);
   //存入用户信息
   if (!window.sessionStorage.getItem("user")){
       return getRequest('/admin/info').then(resp=>{
           if (resp){
               window.sessionStorage.setItem('user',JSON.stringify(resp));
               store.commit('INIT_ADMIN',resp);
               //注入聊天当前对象
              store.state.currentAdmin=resp;
               next();
           }
       })
   }
   next();
 }else {
     //木有登录的时候
     if (to.path=='/'){
         next();
     }else{
         //先让她登录再跳转
         next('/?redirect='+to.path);
     }
 }
})



new Vue({
  router,
    store,
  render: h => h(App)
}).$mount('#app')
